// 云函数入口文件
const cloud = require('wx-server-sdk')
var rq = require('request-promise')

cloud.init()

// 云函数入口函数
exports.main = async(event, context) => {
  const logger = cloud.logger()
  var url = 'http://apis.juhe.cn/simpleWeather/query?key=63e112f49617054c7c4b0e1627a7723f';
  logger.error({
    vurl: url
  })
  var options = {
    method: 'POST',
    uri: url,
    form: {
      city: event.city
    },
    headers: {
      'content-type': 'application/x-www-form-urlencoded'
    }
  };
  var res = rq(options).then(html => {
    return html;
  }).catch(err => {
    console.log(err);
  })
  return res
}